package com.raul.prueba.biblioteca.servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.raul.prueba.biblioteca.servlets.vo.VOPrestamo;
/**
 * Servlet implementation class PrestamoServlet
 */
public class PrestamoServlet extends HttpServlet {

        /**
	 * 
	 */
	private static final long serialVersionUID = -110641267391778658L;

		/**
         * @see HttpServlet#HttpServlet()
         */
        public PrestamoServlet() {
                super();
                // TODO Auto-generated constructor stub
        }

        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
         *      response)
         */
        protected void doGet(HttpServletRequest request,
                        HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
        }

        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
         *      response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String accion = request.getParameter("accion");
        List<VOPrestamo> listaP = (List<VOPrestamo>) request.getSession().getAttribute("listaPrestamo");
        VOPrestamo bus = new VOPrestamo();
        bus.setId(request.getParameter("ID"));
        bus.setDisponible(request.getParameter("Disponible"));
        if (accion.equals("pedir")) {
                for (VOPrestamo obj : listaP) {
                        if (obj.getId().equals(bus.getId())) {
                                obj.setDisponible(bus.getDisponible());
                                break;
                        }
                }
        }
        response.sendRedirect("prestamo/prestamo.jsp");
        }

}